



//
//  PostNaviVC.m
//  PostDelivery
//
//  Created by wmz on 2020/6/18.
//  Copyright © 2020 wmz. All rights reserved.
//

#import "PostNaviVC.h"
#import "SAViewControllerProtocol.h"
#import "BaseVC.h"
@interface PostNaviVC ()<UINavigationControllerDelegate,UIGestureRecognizerDelegate>


@end

@implementation PostNaviVC

- (void)viewDidLoad {
    [super viewDidLoad];
    if (@available(iOS 15.0, *)) {
        UINavigationBarAppearance *barApp = [UINavigationBarAppearance new];
        barApp.backgroundEffect = nil;
        barApp.backgroundColor = wColor_white;
        barApp.shadowColor = nil;
        self.navigationBar.scrollEdgeAppearance = barApp;
        self.navigationBar.standardAppearance = barApp;
    }else{
        self.navigationBar.barTintColor = wColor_white;
    }
    //设置代理
    self.delegate = self;
    
}


- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
    //隐藏导航栏
    BOOL noNav = NO;
    if ([viewController conformsToProtocol:@protocol(SAViewControllerProtocol)]) {
        BaseVC *VC = (BaseVC*)viewController;
        if ([VC customNaviType] == SAViewControllerNaviTypeHide) {
            noNav = YES;
        }else if ([VC customNaviType] == SAViewControllerNaviTypeCustomColor) {
            if (@available(iOS 15.0, *)) {
                navigationController.navigationBar.scrollEdgeAppearance.backgroundColor = [VC customNaviColor];
                navigationController.navigationBar.standardAppearance.backgroundColor = [VC customNaviColor];
            }else{
                navigationController.navigationBar.barTintColor = [VC customNaviColor];
            }
        }else if ([VC customNaviType] == SAViewControllerNaviTypeNormal) {
            if (@available(iOS 15.0, *)) {
                navigationController.navigationBar.scrollEdgeAppearance.backgroundColor = wColor_white;
                navigationController.navigationBar.standardAppearance.backgroundColor = wColor_white;
            }else{
                navigationController.navigationBar.barTintColor = wColor_white;
            }
        }
        if ([VC respondsToSelector:@selector(naviTranslate)]) {
            navigationController.navigationBar.translucent = [VC naviTranslate];
        }
    }
    //隐藏导航栏后会导致边缘右滑返回的手势失效，需要重新设置一下这个代理
    navigationController.interactivePopGestureRecognizer.delegate = self;
    //设置控制器是否要隐藏导航栏
    [navigationController setNavigationBarHidden:noNav animated:YES];
}

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{
    return self.childViewControllers.count > 1;
}


@end
